package com.suny.thread_per_message;

import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class ScheduledExecutorServiceHost {
    private final Helper helper = new Helper();
    private final ScheduledExecutorService scheduledExecutorService;

    public ScheduledExecutorServiceHost(ScheduledExecutorService scheduledExecutorService) {
        this.scheduledExecutorService = scheduledExecutorService;
    }

    public void request(int count, char c) {
        System.out.println("      request(" + count + ", " + c + ") BEGIN");

//        schedule(线程，延迟时间，延迟时间单位)
        scheduledExecutorService.schedule(new Runnable() {
            @Override
            public void run() {
                helper.handle(count, c);
            }
        },3L, TimeUnit.SECONDS);
        System.out.println("      request( " + count + ", " + c + ") END");

    }
}
